<?php
namespace app\controllers;

use app\assets\JselectAsset;

use Yii;
use app\components\BaseController;
use app\components\Api;
use app\components\Loyalty;
use app\components\JselectLoyalty;
use app\components\JselectLoyaltyUAT;
use app\components\Log;
use app\models\Tenant;
use yii\web\ServerErrorHttpException;
use app\models\Artistic;

class ApiController extends BaseController
{
	public $enableCsrfValidation = false;
	
	/**
	 * Dev
	 * Create and Update Customer for webform
	 */
	public function actionCreateAndUpdateCustomerDev()
	{
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
		
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
		
		$post = Yii::$app->request->post();
		if (empty($post['account_id']) || empty($post['username']) || empty($post['password']) || empty($post['card_number']) || empty($post['mobile'])) {
			$this->responseError('data not completed.');return;
		}
		
		$url = 'http://loyalty-uat.xgate.com:8080/index.php/';
		
		$this->bootLoyaltySession(287, $post['account_id'], $post['username'], $post['password'], $url);
	
		$mobile = $post['mobile'];
		$re = Loyalty::customer_get(['mobile' => $mobile]);
		if ($re['status'] == 'success') {
			// update
			$data = [
				'title' => isset($post['title']) ? $post['title'] : '',
				'last_name' => $post['last_name'],
				'first_name' => $post['first_name'],
				'wechat_openid' => $post['wechat_openid'],
				'code' => $re['membership']['code'],
			];
			$r = Loyalty::customer_update($data);
		} else {
			// create
			$data = [
				'title' => isset($post['title']) ? $post['title'] : '',
				'last_name' => $post['last_name'],
				'first_name' => isset($post['first_name']) ? $post['first_name'] : '',
				'mobile' => $post['mobile'],
				'wechat_openid' => $post['wechat_openid'],
				'code' => $post['card_number'],
				'card_number' => $post['card_number'],
			];
			$r = Loyalty::customer_create($data);
		}
		
		if ($r['status'] == 'success') {
			Yii::$app->response->statusCode = 200;
			
			Yii::$app->response->data = [
				'status' => 'success',
			];
			return;
		} else {
			$this->responseError('failed.');
		}
	}
	
	/**
	 * Production
	 * Create and Update Customer for webform
	 */
	public function actionCreateAndUpdateCustomer()
	{
		Log::debug('create and update customer');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		Log::debug('post data', $post);
		if (empty($post['account_id']) || empty($post['username']) || empty($post['password']) || empty($post['card_number']) || empty($post['mobile'])) {
			$this->responseError('data not completed.');return;
		}
	
		$mobile = $post['mobile'];
		$re = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('customer/get result', $re);
		if ($re['status'] == 'success') {
			// update
			$data = [
				'title' => isset($post['title']) ? $post['title'] : '',
				'last_name' => $post['last_name'],
				'first_name' => $post['first_name'],
				'wechat_openid' => $post['wechat_openid'],
				'code' => $re['membership']['code'],
			];
			Log::debug('customer/update data', $data);
			$r = JselectLoyalty::customer_update($data);
			Log::debug('customer/update result', $r);
		} else {
			// create
			$data = [
				'title' => isset($post['title']) ? $post['title'] : '',
				'last_name' => $post['last_name'],
				'first_name' => isset($post['first_name']) ? $post['first_name'] : '',
				'mobile' => $post['mobile'],
				'wechat_openid' => $post['wechat_openid'],
				'code' => $post['card_number'],
				'card_number' => $post['card_number'],
			];
			Log::debug('customer/create data', $data);
			$r = JselectLoyalty::customer_create($data);
			Log::debug('customer/create result', $r);
		}
	
		if ($r['status'] == 'success') {
			Yii::$app->response->statusCode = 200;
				
			Yii::$app->response->data = [
				'status' => 'success',
			];
			return;
		} else {
			$this->responseError('failed.');
		}
	}
	
	/**
	 * Create and Trigger In Jebsen Production
	 * dyson 活动
	 */
	public function actionCreateAndTrigger()
	{
		Log::debug('prod create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
	
		$mobile = $post['mobile'];
		$code = $post['code'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
	
		$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
		];
		Log::debug('prod create customer data', $data);
	
		// 1.Search Customer
		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('prod search customer data', $search);
// 		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		if ($search['status'] == 'success') {
			if ($search['membership']['code'] !== $code){
				$this->responseError('code error.');return;
			}
			$code = $search['membership']['code'];
		} else {
			// 2.Create Customer
// 			$create = JselectLoyalty::customer_create($data);
			$create = JselectLoyalty::customer_create($data);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
		
		Log::debug('code', $code);
		
		// 3.Trigger Earnrule
		$re = JselectLoyalty::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
// 		$re = JselectLoyalty::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
		if ($re['status'] == 'success') {
			Log::debug('prod trigger earnrule success.');
			Yii::$app->response->statusCode = 200;
			Yii::$app->response->data = [
				'status' => 'success',
			];
		} else {
			Log::debug('prod trigger earnrule failed.');
			$this->responseError('trigger earnrule failed.');return;
		}
	}
	
	/**
	 * Create and Trigger In Jebsen UAT
	 */
	public function actionCreateAndTriggerDev()
	{
	Log::debug('prod create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
	
		$mobile = $post['mobile'];
		$code = $post['code'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
	
		$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
		];
		Log::debug('prod create customer data', $data);
	
		// 1.Search Customer
		$search = JselectLoyaltyUAT::customer_get(['mobile' => $mobile]);
		Log::debug('prod search customer data', $search);
// 		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		if ($search['status'] == 'success') {
			if ($search['membership']['code'] != $code){
				$this->responseError('code error.');return;
			}
			$code = $search['membership']['code'];
		} else {
			// 2.Create Customer
// 			$create = JselectLoyalty::customer_create($data);
			$create = JselectLoyaltyUAT::customer_create($data);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
		
		Log::debug('code', $code);
		
		// 3.Trigger Earnrule
		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
// 		$re = JselectLoyalty::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
		if ($re['status'] == 'success') {
			Log::debug('prod trigger earnrule success.');
			Yii::$app->response->statusCode = 200;
			Yii::$app->response->data = [
				'status' => 'success',
			];
		} else {
			Log::debug('prod trigger earnrule failed.');
			$this->responseError('trigger earnrule failed.');return;
		}
	}
	
	// 姐妹淘活动
	public function actionCreateAndTrigger1()
	{
		Log::debug('prod create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
		
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
		
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
		
		$mobile = $post['mobile'];
		$code = $post['code'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
		
		$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
		];
		Log::debug('prod create customer data', $data);
		
		// 1.Search Customer
		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('prod search customer data', $search);
		// 		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		if ($search['status'] == 'success') {
			if ($search['membership']['code'] != $code){
				$this->responseError('code error.');return;
			}
			$code = $search['membership']['code'];
		} else {
			// 2.Create Customer
			// 			$create = JselectLoyalty::customer_create($data);
			$create = JselectLoyalty::customer_create($data);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
		
		Log::debug('code', $code);
		
		// 3.Trigger Earnrule
		$re = JselectLoyalty::trigger_earnrule(['code' => $code, 'event' => 'Send Sister Tao Coupon']);
		// 		$re = JselectLoyalty::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
		if ($re['status'] == 'success') {
			Log::debug('dev trigger earnrule success.');
			Yii::$app->response->statusCode = 200;
			Yii::$app->response->data = [
			'status' => 'success',
			];
		} else {
			Log::debug('prod trigger earnrule failed.');
			$this->responseError('trigger earnrule failed.');return;
		}
	}
	
	// IFC 活动, 只发3张优惠券
	public function actionCreateAndTrigger2()
	{
// 		Log::debug('dev create and trigger start.');
		
		Log::debug('prod create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
		if (!Yii::$app->request->isPost){
			$this->responseError('need post request.');return;
		} 
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}		
		$mobile = $post['mobile'];
		$code = $post['code'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';		
		$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
		];
		Log::debug('prod create customer data', $data);
	
		// 1.Search Customer
// 		$search = JselectLoyaltyUAT::customer_get(['mobile' => $mobile]);
		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('prod search customer data', $search);
		if ($search['status'] == 'success') {
			if ($search['membership']['code'] != $code){
				$this->responseError('code error.');return;
			}
			$code = $search['membership']['code'];
		} else {
			// 2.Create Customer
// 			$create = JselectLoyaltyUAT::customer_create($data);
			$create = JselectLoyalty::customer_create($data);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}	
		Log::debug('code', $code);	
	}
	
	//Double 11 campaign
	public function actionCreateAndTrigger3()
	{
		Log::debug('prod create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
	
		$mobile = $post['mobile'];
		$code = $post['code'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
	
		$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
		];
		Log::debug('prod create customer data', $data);
	
		// 1.Search Customer
// 		$search = JselectLoyaltyUAT::customer_get(['mobile' => $mobile]);
		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('prod search customer data', $search);
		// 		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		if ($search['status'] == 'success') {
// 			if ($search['membership']['code'] != $code){
				$this->responseError('code error.');return;
// 			}
// 			$code = $search['membership']['code'];
		} else {
			// 2.Create Customer
			// 			$create = JselectLoyalty::customer_create($data);
// 			$create = JselectLoyaltyUAT::customer_create($data);
			$create = JselectLoyalty::customer_create($data);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
	
		Log::debug('code', $code);
	}
	
	public function actionCreateOrUpdateProduct(){
		Log::debug('prod create Or update start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
		
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
		
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code']) || empty($post['wechat_openid'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
		
		$mobile = $post['mobile'];
		$code = $post['code'];
		$wechat_openid = $post['wechat_openid'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
		$title = isset($post['title']) ? $post['title'] : '';
		
		Log::debug('test code',$code);
		// 1.Search Customer
		$search = JselectLoyalty::customer_get(['mobile' => $mobile]);
		Log::debug('test search',$search);
		if ($search['status'] == 'success') {
			$code = $search['membership']['code'];
			$update = JselectLoyalty::customer_update(['code' => $code, 'wechat_openid' => $wechat_openid, 'first_name' => $first_name, 'last_name' => $last_name, 'title' => $title]);
			if ($update['status'] != 'success') {
				Log::debug('prod update customer failed.');
				$this->responseError('update customer failed.');return;
			}
		} else {
			$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
			'wechat_openid' => $wechat_openid,
			'title' => $title
			];
			Log::debug('prod create customer data', $data);
			// 2.Create Customer
			$create = JselectLoyalty::customer_create($data);
			Log::debug('create test',$create);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
	}
	
	public function actionCreateOrUpdate(){
		Log::debug('prod create Or update start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		if (empty($post['mobile']) || empty($post['code']) || empty($post['wechat_openid'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
	
		$mobile = $post['mobile'];
		$code = $post['code'];
		$wechat_openid = $post['wechat_openid'];
		$first_name = isset($post['first_name']) ? $post['first_name'] : '';
		$last_name = isset($post['last_name']) ? $post['last_name'] : '';
		$title = isset($post['title']) ? $post['title'] : '';
	
		Log::debug('test code',$code);
		// 1.Search Customer
		$search = JselectLoyaltyUAT::customer_get(['mobile' => $mobile]);
		Log::debug('test search',$search);
		if ($search['status'] == 'success') {
			$code = $search['membership']['code'];
			$update = JselectLoyaltyUAT::customer_update(['code' => $code, 'wechat_openid' => $wechat_openid, 'first_name' => $first_name, 'last_name' => $last_name, 'title' => $title]);
			if ($update['status'] != 'success') {
				Log::debug('prod update customer failed.');
				$this->responseError('update customer failed.');return;
			}
		} else {
			$data = [
			'mobile' => $mobile,
			'code' => $code,
			'card_number' => $code,
			'first_name' => $first_name,
			'last_name' => $last_name,
			'wechat_openid' => $wechat_openid,
			'title' => $title
			];
			Log::debug('prod create customer data', $data);
			// 2.Create Customer
			$create = JselectLoyaltyUAT::customer_create($data);
			Log::debug('create test',$create);
			if ($create['status'] != 'success') {
				Log::debug('prod create customer failed.');
				$this->responseError('create customer failed.');return;
			}
		}
	}
	
	/**
	 * Trigger Earnrule In Jebsen UAT
	 */
	public function actionTriggerEarnruleDev()
	{
		Log::debug('create and triiger start.');
		Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
	
		if (!Yii::$app->request->isPost) {
			$this->responseError('need post request.');return;
		}
	
		$post = Yii::$app->request->post();
		if (empty($post['code'])) {
			Log::debug('data not completed.');
			$this->responseError('data not completed.');return;
		}
	
		$code = $post['code'];
	
		// 1.Get Customer
		$re = JselectLoyaltyUAT::customer_get(['code' => $code]);
		if ($re['status'] == 'success') {
			// 2.Trigger Earnrule
			$re = JselectLoyaltyUAT::trigger_earnrule(['code' => $code, 'event' => 'Dyson Survey Coupon']);
			if ($re['status'] == 'success') {
				Log::debug('trigger earnrule success.');
				Yii::$app->response->statusCode = 200;
	
				Yii::$app->response->data = [
					'status' => 'success',
				];
			} else {
				Log::debug('trigger earnrule failed.');
				$this->responseError('trigger earnrule failed.');return;
			}
		} else {
			Log::debug('no customer exists.');
			$this->responseError('no customer exists.');return;
		}
	}
	
	/**
	 * bootLoyaltySession
	 * @param unknown_type $tenant_id
	 * @param unknown_type $account_id
	 * @param unknown_type $username
	 * @param unknown_type $password
	 * @param unknown_type $url
	 */
	protected function bootLoyaltySession($tenant_id, $account_id, $username, $password, $url)
	{
		$session = Yii::$app->session;
		$loyaltyConfig = [
			'tenant_id' => $tenant_id,
			'loyalty_accountid' => $account_id,
			'loyalty_username' => $username,
			'loyalty_password' => $password,
			'loyalty_url' => $url,
		];
		$session->set('loyaltyConfig', $loyaltyConfig);
	}
		
	/**
	 * bootstrap function for basic appid, userinfo
	 * @param string $appid
	 * @param array $userInfo
	 * @throws ServerErrorHttpException
	 */
	protected function bootstrap($appid)
	{
		Log::debug('Campaign bootstrap GET FIELDS', $_GET);
				
		if (empty($appid)) {
			throw new ServerErrorHttpException('appid not found');
		}
		// 重要！获取appid，作为全局支持
		$this->setAppid($appid);
		
		// 设置identifier
		$tenant = Tenant::find()->where(['appid' => $appid])->one();
		
		if (empty($tenant->identifier)) {
			throw new ServerErrorHttpException('identifier not found');
		}
		$this->setIdentifier($tenant->identifier);
		
		// 设置loyalty config
		if (empty($tenant->tenant_id) || empty($tenant->loyalty_accountid) || empty($tenant->loyalty_username) || empty($tenant->loyalty_password)) {
			throw new ServerErrorHttpException('loyalty config not found');
		} else {
			$session = Yii::$app->session;
			$loyaltyConfig = [
				'tenant_id' => $tenant->tenant_id,
				'app_id' => $tenant->appid,
				'loyalty_accountid' => $tenant->loyalty_accountid,
				'loyalty_username' => $tenant->loyalty_username,
				'loyalty_password' => $tenant->loyalty_password,
				'loyalty_url' => $tenant->loyalty_url,
			];
			$session->set('loyaltyConfig', $loyaltyConfig);
		}
	}
	
	public function actionTestUat()
	{ 
// 		$re = JselectLoyaltyUAT::list_coupon(['coupon_id' => 22]);
// 		$re = JselectLoyaltyUAT::generator(['hash' => 'customer/create']);
// 		$re = JselectLoyaltyUAT::customer_search([]);
// 		$re = JselectLoyaltyUAT::customer_get(['mobile' => '18227693267']); // quincy->13632704647  fanny->13570341201
// 		$re = JselectLoyaltyUAT::customer_update(['code' => '001000115905', 'wechat_openid' => '']); // 001000115653  001000113798
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000119971']);
		$re = JselectLoyaltyUAT::customer_delete(['code' => '001000115945']);
// 		$params = [
// 			'code' => '001000119971',
// 			'mobile'  => '8618227693267',
// 			'first_name'  => 'Chris',
// 			'last_name' => 'Kuang',
// 			'birth_yyyy' => '1904',
// 			'birth_mm' => '01',
// 			'birth_dd' => '01',
// 		];
// 		$re = JselectLoyaltyUAT::customer_create($params);
// 		$re = JselectLoyaltyUAT::list_coupon(['coupon_id' => 42]);
		echo '<pre>'; print_r($re);die;
	}
	
	public function actionTest()
	{
// 				$re = JselectLoyalty::list_coupon(['coupon_id' => 25]);
		// 		$re = JselectLoyaltyUAT::generator(['hash' => 'customer/create']);
// 				$re = JselectLoyalty::customer_search([]);
// 		$re = JselectLoyalty::customer_get(['mobile' => '8613711971322']); // 001000115653  001000113798
				$re = JselectLoyalty::get_coupon_codes(['code' => '001000116003']);
// 		$re = JselectLoyalty::customer_delete(['code' => '001000115973']);
// 				$params = [
// 					'mobile'  => '18227693267',
// 					'code' => '001000116101',
// 					'first_name'  => 'Chris',
// 					'last_name' => 'Kuang',
// 					'birth_yyyy' => '1904',
// 					'birth_mm' => '00',
// 					'birth_dd' => '00',
// 				];
// 				$re = JselectLoyalty::customer_create($params);
// 		$re = JselectLoyalty::customer_update($params);
		echo '<pre>'; print_r($re);die;
	}
	
	/**
	 * response
	 * @param string $status
	 * @param string $msg
	 */
	private function responseError($msg)
	{
		Yii::$app->response->statusCode = 200;
	
		Yii::$app->response->data = [
			'status' => 'error',
			'errormsg' => $msg,
		];
	}
	
	/**
	 * 创建coupon的字段对应关系
	 * 
	 * name - 卷名，用来匹配 type
	 * description - 券的文字描述 / 或折扣数 / 或金钱数
	 * description_c - 核销按钮上方文字，可以为空
	 * terms - 使用条款
	 * brand - 1或空=自营门店 2=第三方门店
	 */
	public function actionT()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1 
		// Artistic&co campaign_id = 5
		// production Artistic&co campaign_id = 3
//     	$re = Loyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Artistic&co 面部产品体验' ,'campaign_name' => 'Artistic&co 面部产品体验']);
    	
		// 2.1
		// store
// 		$re = Loyalty::store_get([]);
		
    	// 2.2
    	// Artistic&co coupon_id = 28
    	// production Artistic&co [DC00101806003] coupon_id = 16
//     	$re = Loyalty::coupon_create(['campaign_id' => 3, 'name' => 'Artistic&co 面部产品体验券', 'type' => 'token', 'description' => 'Artistic&co', 'description_c' => '免费领取', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-06', 'end_date' => '2018-08-16', 'store_id' => '1, 2, 3, 4, 5, 7, 8, 9, 10, 11']);

		// 2.3
		// send old member coupon
// 		$barcode_pattern = [
// 			'pattern_type' => 'fixed',
// 			'fixed_value' => '',
// 		];
		// production 九折券 [DC00101806001] coupon_id = 17
// 		$re = Loyalty::coupon_create(['campaign_id' => 2, 'autocreate' => 1, 'name' => '九折券', 'type' => 'token', 'description' => '10', 'description_c' => '免费领取', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-06', 'end_date' => '0000-00-00', 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'barcode_pattern' => json_encode($barcode_pattern)]);
		// production ￥100 [DC00101823801] coupon_id = 18
// 		$re = Loyalty::coupon_create(['campaign_id' => 2, 'autocreate' => 1, 'name' => '￥100', 'type' => 'token', 'description' => '100', 'description_c' => '满2000使用', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-06', 'end_date' => '2019-08-06', 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'barcode_pattern' => json_encode($barcode_pattern)]);
		// production 帆布袋 [DC00101806002] coupon_id = 19
// 		$re = Loyalty::coupon_create(['campaign_id' => 2, 'name' => '帆布袋', 'type' => 'token', 'description' => '定制帆布袋', 'description_c' => '免费领取', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-06', 'end_date' => '2019-08-06', 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'barcode_pattern' => json_encode($barcode_pattern)]);

		// 3
		// find coupon
// 		$re = Loyalty::list_coupon();

		// 4
		// list earnrule
// 		$re = Loyalty::list_earnrule([]);

		// 5
		// Artistic&co earnrule_id = 9
		// production Artistic&co earnrule_id = 1
// 		$re = Loyalty::earnrule_create(['campaign_id' => 3, 'active' => 'yes', 'description' => 'Send Artistic&co Coupon', 'event' => 'Send Artistic&co Coupon', 'activity_rule' => 'all time']);
		// production Customer Registration earnrule_id = 2
// 		$re = Loyalty::earnrule_create(['campaign_id' => 2, 'active' => 'yes', 'description' => 'New Member Registration', 'trigger_on' => 'Customer Registration', 'activity_rule' => 'all time']);

		// 6
// 		$re = Loyalty::add_rule_to_item(['earnrule_id' => 2, 'coupon_id' => 19, 'reward_qty' => '1']);
    	
    	// add hoc
// 		$re = Loyalty::trigger_earnrule(['code' => '3329901460678094','event' => 'Send Artistic&co Coupon']);
//     	$re = Loyalty::remove_rule_from_item(['earnrule_id' => 6,'coupon_id' => 25]);
//     	$re = Loyalty::update_earnrule(['earnrule_id' => '6', 'active' => 'yes']);
// 		$re = Loyalty::customer_search(['first_name' => 'quincy']);
// 		$re = Loyalty::customer_get(['mobile' => '8617311355059']);
// 		$re = Loyalty::customer_get(['mobile' => '8613828495068']);
// 		$re = Loyalty::customer_get(['mobile' => '8613980949494']);
// 		$re = Loyalty::customer_create(['code' => 'WilliamTest5', 'wechat_openid' => 'olX1auIdmRsTN0WGYfDdjwAH0qU5', 'mobile' => '8617713666665', 'last_name' => 'Test']);
// 		$re = Loyalty::customer_update(['code' => '001000112590', 'wechat_openid' => '']);
// 		$re = Loyalty::customer_delete(['code' => 'WilliamTest']);
// 		$re = Loyalty::get_coupon_codes(['code' => 'WilliamTest1']);
// 		$re = Loyalty::coupon_update(['campaign_id'=> 3, 'coupon_id'=> 16, 'description' => 'Artistic&Co.<br>面部产品', 'start_date' => '2018-08-06 00:00:00', 'end_date' => '2018-09-16 23:59:59']);
// 		$re = Loyalty::coupon_update(['campaign_id'=> 2, 'coupon_id'=> 19, 'barcode_pattern' => json_encode($barcode_pattern)]);
// 		$re = Loyalty::campaign_list([]);
// 		$re = Loyalty::customer_search([]);
//     	$this->bp($re);
	}
	
	/**
	 * Dyson Campaign UAT
	 */
	public function actionT1()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		// uat campaign_id 7
// 		$re = Loyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Dyson Survey' ,'campaign_name' => 'Dyson Survey']);
		
		// 2
		// coupon
		// uat coupon_id 30
// 		$re = Loyalty::coupon_create(['campaign_id' => 7, 'name' => '美肤疗程', 'type' => 'token', 'description' => '美肤疗程', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited', 'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00', 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11']);
		// uat coupon_id 31
// 		$re = Loyalty::coupon_create(['campaign_id' => 7, 'name' => '彩色手工面条', 'type' => 'token', 'description' => '彩色手工面条', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00', 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11']);
		
		// 3
		// earnrule
		// uat earnrule_id 13 [Dyson Survey Coupon]
// 		$re = Loyalty::earnrule_create(['campaign_id' => 7, 'active' => 'yes', 'description' => 'Send Coupon to Dyson member', 'event' => 'Dyson Survey Coupon', 'activity_rule' => 'all time']);
		
		// 4
		// add earnrule to item
// 		$re = Loyalty::add_rule_to_item(['earnrule_id' => 13, 'coupon_id' => 31, 'validtime' => '90', 'unit' => 'day']);
	
		// add hoc
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112581', 'event' => 'Dyson Survey Coupon']);
// 		$re = JselectLoyaltyUAT::list_earnrule([]);
// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => 13,'coupon_id' => 31]);
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112581']);
// 		$re = JselectLoyaltyUAT::customer_search(['wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc']);
// 		$re = JselectLoyaltyUAT::customer_update(['code' => '000019', 'wechat_openid' => '']);
// 		$re = JselectLoyaltyUAT::customer_search(['code' => 'f2']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'william3', 'wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0', 'first_name' => 'william', 'last_name' => 'sun']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'q2', 'card_number' => 'q2', 'mobile' => '8613632704647', 'wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA', 'first_name' => 'q', 'last_name' => 'q']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'f2', 'card_number' => 'f2', 'mobile' => '8613570341201', 'wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc', 'first_name' => 'f', 'last_name' => 'f']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'a2', 'card_number' => 'a2', 'mobile' => '8613333333333', 'wechat_openid' => 'o2Rmrt5U54B4kkWj5YfQ67g3V3xM', 'first_name' => 'a', 'last_name' => 'a']);
// 		$re = JselectLoyaltyUAT::customer_delete(['code' => 'f1']);
// 		$re = JselectLoyaltyUAT::coupon_update(['campaign_id'=> 7, 'coupon_id'=> 30, 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14', 'autocreate' => '1', 'usage_limit' => '2']);
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112579']);
		$this->bp($re);
	}
	
	/**
	 * Dyson Campaign Production
	 */
	public function actionP1()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		// campaign_id 4
// 		$re = JselectLoyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Dyson Survey' ,'campaign_name' => 'Dyson Survey']);
	
		// 2
		// coupon
		// coupon_id 20
// 		$re = JselectLoyalty::coupon_update([
// 				'campaign_id' => 4, 'coupon_id' => 20, 'type' => 'token', 
// 				'name' => '美肤疗程', 'description' => '美肤疗程', 'description_c' => '', 
// 				'autocreate' => '1', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited', 
// 				'start_date' => '2018-08-028 00:00:00', 'end_date' => '2099-12-31 23:59:59', 
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'brand' => '1',
// 				'terms' => '1. 体验券有效期：自收到优惠券的三个月内有效
// 2. 体验券不可转让、退换或者兑换现金
// 3. 本券仅适用于J SELECT中国大陆代理消费品业务
// 4. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 5. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);
		// coupon_id 21
// 		$re = JselectLoyalty::coupon_update([
// 				'campaign_id' => 4, 'coupon_id' => 21, 'type' => 'token', 
// 				'name' => '彩色手工面条', 'description' => '彩色手工面条', 'description_c' => '', 
// 				'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 
// 				'start_date' => '2018-08-028 00:00:00', 'end_date' => '2099-12-31 23:59:59', 
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'brand' => '1',
// 				'terms' => '1. 体验券有效期：自收到优惠券的三个月内有效
// 2. 体验券不可转让、退换或者兑换现金
// 3. 本券仅适用于J SELECT中国大陆代理消费品业务
// 4. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 5. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);
	
		// 3
		// earnrule
		// earnrule_id 3 [Dyson Survey Coupon]
// 		$re = JselectLoyalty::earnrule_create(['campaign_id' => 4, 'active' => 'yes', 'description' => 'Send Coupon to Dyson member', 'event' => 'Dyson Survey Coupon', 'activity_rule' => 'all time']);
	
		// 4
		// add earnrule to item
// 		$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => 3, 'coupon_id' => 21, 'validtime' => '90', 'unit' => 'day']);
	
		// add hoc
// 		$re = JselectLoyalty::trigger_earnrule(['code' => '001000112581', 'event' => 'Dyson Survey Coupon']);
// 		$re = JselectLoyalty::list_earnrule([]);
// 		$re = JselectLoyalty::remove_rule_from_item(['earnrule_id' => 3,'coupon_id' => 21]);
// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000112581']);
// 		$re = JselectLoyalty::customer_search(['code' => '17713607873']);
// 		$re = JselectLoyalty::customer_search(['mobile' => '8613632704647']);
// 		$re = JselectLoyalty::customer_create(['code' => 'william3', 'wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0', 'first_name' => 'william', 'last_name' => 'sun']);
// 		$re = JselectLoyalty::customer_create(['code' => 'q2', 'card_number' => 'q2', 'mobile' => '8613632704647', 'wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA', 'first_name' => 'q', 'last_name' => 'q']);
// 		$re = JselectLoyalty::customer_create(['code' => 'f2', 'card_number' => 'f2', 'mobile' => '8613570341201', 'wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc', 'first_name' => 'f', 'last_name' => 'f']);
// 		$re = JselectLoyalty::customer_create(['code' => 'a2', 'card_number' => 'a2', 'mobile' => '8613333333333', 'wechat_openid' => 'o2Rmrt5U54B4kkWj5YfQ67g3V3xM', 'first_name' => 'a', 'last_name' => 'a']);
// 		$re = JselectLoyalty::customer_delete(['code' => '001000112594']);
// 		$re = JselectLoyalty::coupon_update(['campaign_id'=> 7, 'coupon_id'=> 30, 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14', 'autocreate' => '1', 'usage_limit' => '2']);
// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000112579']);
		$this->bp($re);
	}
	
	/**
	 * Ciabatta Bread Campaign UAT
	 */
	public function actionT2()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		// uat campaign_id 9
// 		$re = JselectLoyaltyUAT::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Temporary Campaign' ,'campaign_name' => 'Temporary Campaign']);
	
		// 2
		// store
		// uat store_id 15
// 		$re = JselectLoyaltyUAT::store_create(['code' => 'LMZKF01', 'storename'=> '鲁马滋咖啡' ,'redeem_password' => '0823', 'address1' => '上海徐汇区兴国路372弄1号']);
// 		$re = JselectLoyaltyUAT::store_get([]);
		
		// 2
		// coupon
		// uat coupon_id 32
// 		$re = JselectLoyaltyUAT::coupon_create(['campaign_id' => 9, 'name' => '手工Ciabatta恰巴塔面包券', 'type' => 'token', 'description' => '凭电子券到鲁马滋兴国路购买每日精选咖啡一杯(60元) ，可免费获赠手工Ciabatta恰巴塔面包一份 (价值25元) 。', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-27 00:00:00', 'end_date' => '2018-09-21 23:59:59', 'store_id' => '15', 'terms' => '1. 有效期为：2018年8月27日到9月21日，星期一到星期五早上10点到下午1点
// 2. 面包每天限量10份，先到先得
// 2. 電电券不可转让、退换或者兑换现金
// 3. 本券仅适用于J SELECT中国大陆代理消费品业务']);

// 		$re = JselectLoyaltyUAT::coupon_update(['campaign_id' => 9, 'coupon_id'=> 32, 'name' => '手工Ciabatta恰巴塔面包券', 'thumbnail_url' => 'https://imgsrv1.mailer08.net/images/dGVuYW50Mjg3YWRtaW4_/store/rumors.png', 'type' => 'token', 'brand' => '2', 'description_c' => '', 'description' => '手工Ciabatta恰巴塔面包券', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-08-27 00:00:00', 'end_date' => '2018-09-21 23:59:59', 'store_id' => '15', 'terms' => '凭电子券到鲁马滋兴国路购买每日精选咖啡一杯(60元) ，可免费获赠手工Ciabatta恰巴塔面包一份 (价值25元) 。
// 1. 有效期为：2018年8月27日到9月21日，星期一到星期五早上10点到下午1点
// 2. 面包每天限量10份，先到先得
// 2. 电子券不可转让、退换或者兑换现金
// 3. 本券仅适用于J SELECT中国大陆代理消费品业务']);

		// coupon_id 5 帆布袋
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'campaign_id' => 1, 'coupon_id' => 5, 'type' => 'token', 'brand' => '1',
// 				'name' => '帆布袋', 'description' => '定制帆布袋', 'description_c' => '免费领取',   
// 				'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 
// 				'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00', 
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13', 'terms' => '1.权益有效期：一年（时间按照领券日起算）
// 活动期间，J SELECT会员到店即可领取定制购物袋一个
// 2.本礼品券J SELECT全国门店通用
// 3.每位会员仅可获赠会员尊享好礼一次
// 4.会员尊享好礼数量有限，先到先得，送完即止
// 5.会员尊享好礼不可转让、退换或者兑换现金
// 6.本优惠仅适用于J SELECT中国大陆代理消费品业务
// 7.捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 8.如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);

		// coupon_id 21 ￥100
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'campaign_id' => 1, 'coupon_id' => 21, 'type' => 'token', 'brand' => '1',
// 				'name' => '￥100', 'description' => '100', 'description_c' => '满2000使用',
// 				'usage_limit' => '0', 'number_of_coupons' => 'unlimited', 'autocreate' => '1',
// 				'start_date' => '2018-08-24 00:00:00', 'end_date' => '2099-12-31 23:59:59',
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
// 				'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => 'DC00101823801']),
// 				'terms' => '1. 活动有效期：一年（时间按照领券日起算）
// 活动期间，J SELECT会员到店立享100元折扣(部分品牌满2000元立减)
// 2.本折扣券J SELECT全国门店通用
// 3.会员尊享好礼数量有限，先到先得，送完即止
// 4.会员尊享好礼不可转让、退换或者兑换现金
// 5.本优惠仅适用于J SELECT中国大陆代理消费品业务
// 6.捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 7.如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权
// * 现金券使用规则：仅供J SELECT会员专享，可在J SELECT及J SELECT +门店单笔消费满2000元立减100元（不叠加），配件除外，当次核销可用，不可与门店其他活动叠加使用']);

// 		// coupon_id 4 九折券
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'campaign_id' => 1, 'coupon_id' => 4, 'type' => 'token', 'brand' => '1',
// 				'name' => '九折券', 'description' => '10', 'description_c' => '',
// 				'usage_limit' => '0', 'number_of_coupons' => 'unlimited', 'autocreate' => '1',
// 				'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00',
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
// 				'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 				'terms' => '1.权益有效期：长期有效
// 活动期间，J SELECT会员到店立享购物九折(部分品牌)
// 2.本折扣券J SELECT全国门店通用 
// 3.会员尊享好礼数量有限，先到先得，送完即止
// 4.会员尊享好礼不可转让、退换或者兑换现金
// 5.本优惠仅适用于J SELECT中国大陆代理消费品业务
// 6.捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 7.如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);

		// coupon_id 28 Artistic&Co. 面部产品体验券
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'campaign_id' => 5, 'coupon_id' => 28, 'type' => 'token', 'brand' => '1',
// 				'name' => 'Artistic&Co. 面部产品体验券', 'description' => 'Artistic&Co.<br>面部产品', 'description_c' => '',
// 				'usage_limit' => '1', 'number_of_coupons' => 'unlimited',
// 				'start_date' => '2018-08-16 00:00:00', 'end_date' => '2018-09-16 23:59:59',
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
// 				'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 				'terms' => '1.活动有效期：2018年8月6日-2018年9月16日
// 活动期间，J SELECT会员到店立享Artistic&Co. 面部产品体验
// 2.本体验券J SELECT全国门店通用（上海伊势丹店除外）
// 3.一张体验券仅供一名会员体验一次 
// 4.会员尊享体验不可转让、退换或者兑换现金 
// 5.捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 6.如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);

		// 3
		// earnrule
		// uat earnrule_id 14 [Send Ciabatta Bread Coupon]
// 		$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9, 'active' => 'yes', 'description' => 'Send Ciabatta Bread Coupon', 'event' => 'Send Ciabatta Bread Coupon', 'activity_rule' => 'all time']);
	
		// 4
		// add earnrule to item
// 		$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => 3, 'coupon_id' => 28]);
	
		// add hoc
// 		$re = JselectLoyaltyUAT::generator(['hash' => 'coupon/create_coupon']);
// 		$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => 6, 'active' => 'no']);
// 		$re = JselectLoyaltyUAT::list_coupon([]);
// 		$re = JselectLoyaltyUAT::customer_delete(['coupon_id' => '23']);
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112603', 'event' => 'Send Ciabatta Bread Coupon']);
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112603', 'event' => 'Send Artistic&co Coupon']);
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => 'william13', 'event' => 'Dyson Survey Coupon']);
// 		$re = JselectLoyaltyUAT::list_earnrule([]);
// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => 2, 'coupon_id' => 4]);
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112605']);
// 		$re = JselectLoyaltyUAT::customer_search(['wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0']);
// 		$re = JselectLoyaltyUAT::customer_search(['wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA']);
// 		$re = JselectLoyaltyUAT::customer_update(['code' => '001000112603', 'mobile' => '8617713607873']);
// 		$re = JselectLoyaltyUAT::customer_search(['mobile' => '15921705708']);
// 		$re = JselectLoyaltyUAT::customer_get(['mobile' => '8615921705708']);
//      cara 15918725639 tomes 8615196359975
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'william13', 'wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0', 'first_name' => 'william', 'last_name' => 'sun']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'q2', 'card_number' => 'q2', 'mobile' => '8613632704647', 'wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA', 'first_name' => 'q', 'last_name' => 'q']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'f2', 'card_number' => 'f2', 'mobile' => '8613570341201', 'wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc', 'first_name' => 'f', 'last_name' => 'f']);
// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'a2', 'card_number' => 'a2', 'mobile' => '8613333333333', 'wechat_openid' => 'o2Rmrt5U54B4kkWj5YfQ67g3V3xM', 'first_name' => 'a', 'last_name' => 'a']);
// 		$re = JselectLoyaltyUAT::customer_delete(['code' => '001000112581']);
// 		$re = JselectLoyaltyUAT::coupon_update(['campaign_id'=> 7, 'coupon_id'=> 30, 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14', 'autocreate' => '1', 'usage_limit' => '2']);
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112579']);
		$this->bp($re);
	}
	
	/**
	 * Bread Campaign
	 */
	public function actionP2()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		// campaign_id 13
// 		$re = JselectLoyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Temporary Campaign' ,'campaign_name' => 'Temporary Campaign']);
		
		// 2
		// store
		// store_id 12
// 		$re = JselectLoyalty::store_create(['code' => 'LMZKF01', 'storename'=> '鲁马滋咖啡' ,'redeem_password' => '0823', 'address1' => '上海徐汇区兴国路372弄1号']);
// 		$re = JselectLoyalty::store_get([]);
		
		// 2
// coupon
		// coupon_id 20
// 		$re = JselectLoyaltUAT::coupon_update([
// 				'campaign_id' => 4, 'coupon_id' => 30, 'type' => 'token', 
// 				'name' => '美肤疗程', 'description' => '美肤疗程', 'description_c' => '', 
// 				'autocreate' => '1', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited', 
// 				'start_date' => '2018-08-028 00:00:00', 'end_date' => '2099-12-31 23:59:59', 
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'brand' => '1',
// 				'terms' => '1. 该体验券可享受的服务项目有：
// 								 a. 面部深层胶原蛋白重生（30分钟）; b. 面部深层清洁及营养导入（30分钟）; c. 局部脱毛疗程（20分钟）; d. 溢脂性脱发抑制及毛囊刺激疗程（15分钟）
// 							2. 体验券有效期：自收到优惠券的三个月内有效
// 							3. 体验券不可转让、退换或者兑换现金
// 							4. 本券仅适用于J SELECT中国大陆代理消费品业务
// 							5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 							6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权'
// 				]);


		// 3
		// earnrule
		// earnrule_id 4 [Send Ciabatta Bread Coupon]
// 		$re = JselectLoyalty::earnrule_create(['campaign_id' => 13, 'active' => 'yes', 'description' => 'Send Ciabatta Bread Coupon', 'event' => 'Send Ciabatta Bread Coupon', 'activity_rule' => 'all time']);
		
		// 4
		// add earnrule to item
// 		$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => 4, 'coupon_id' => 22]);
		
		// add hoc
		// 		$re = JselectLoyaltyUAT::generator(['hash' => 'coupon/create_coupon']);
		// 		$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => 6, 'active' => 'no']);
		// 		$re = JselectLoyaltyUAT::list_coupon(['coupon_id' => 21]);
		// 		$re = JselectLoyaltyUAT::customer_delete(['coupon_id' => '23']);
// 				$re = JselectLoyalty::trigger_earnrule(['code' => '001000114445', 'event' => 'Send Ciabatta Bread Coupon']);
		// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112603', 'event' => 'Send Artistic&co Coupon']);
		// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => 'william13', 'event' => 'Dyson Survey Coupon']);
		// 		$re = JselectLoyaltyUAT::list_earnrule([]);
		// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => 2, 'coupon_id' => 4]);
// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000115558']);
// 				$re = JselectLoyalty::customer_search(['code' => '001000113705']);
		// 		$re = JselectLoyaltyUAT::customer_search(['wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA']);
// 				$re = JselectLoyalty::customer_update(['code' => '00d0115736', 'wechat_openid' => '']);
// 				$re = JselectLoyalty::customer_search(['mobile' => '18723836813']);
		//      cara 15918725639 tomes 8615196359975 aaron 18723836813
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'william13', 'wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0', 'first_name' => 'william', 'last_name' => 'sun']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'q2', 'card_number' => 'q2', 'mobile' => '8613632704647', 'wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA', 'first_name' => 'q', 'last_name' => 'q']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'f2', 'card_number' => 'f2', 'mobile' => '8613570341201', 'wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc', 'first_name' => 'f', 'last_name' => 'f']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'a2', 'card_number' => 'a2', 'mobile' => '8613333333333', 'wechat_openid' => 'o2Rmrt5U54B4kkWj5YfQ67g3V3xM', 'first_name' => 'a', 'last_name' => 'a']);
		// 		$re = JselectLoyaltyUAT::customer_delete(['code' => '001000112581']);
		// 		$re = JselectLoyaltyUAT::coupon_update(['campaign_id'=> 7, 'coupon_id'=> 30, 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14', 'autocreate' => '1', 'usage_limit' => '2']);
		// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112579']);
		$this->bp($re);
	}
	
	
	/**
	 * Bread Campaign
	 */
	public function actionP3()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		//  staging campaign_id = 9
		//  production campaign_id = 13
		// 		$re = JselectLoyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Temporary Campaign' ,'campaign_name' => 'Temporary Campaign']);
// 				$re = JselectLoyaltyUAT::campaign_list([]);
	
		// 2
		// store
		// staging store_id = 14
		// production store_id = 11
		// 		$re = JselectLoyalty::store_create(['code' => 'LMZKF01', 'storename'=> '鲁马滋咖啡' ,'redeem_password' => '0823', 'address1' => '上海徐汇区兴国路372弄1号']);
// 				$re = JselectLoyaltyUAT::store_get([]);
// 				$re = JselectLoyalty::store_get([]);
				
	
		// 2.1 创建广发内部员工券 
		// staging store_id = 14  campaign_id = 9 创建结果 staging coupon_id = 34
		// production store_id = 11  campaign_id = 13 创建结果 staging coupon_id = 23 门店绑定错误，需要重新绑定
// 				$re = JselectLoyaltyUAT::coupon_create(['campaign_id' => 9, 'name' => '广发内部员工优惠券', 'type' => 'token', 'description' => 'IGC', 'description_c' => '亲临IGC购买任意产品满2000即减200.', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-09-01', 'end_date' => '2018-11-30', 'store_id' => '14']);
// 		$re = JselectLoyalty::coupon_create(['campaign_id' => 13, 'name' => '广发内部员工优惠券', 'type' => 'token', 'description' => 'IGC', 'description_c' => '亲临IGC购买任意产品满2000即减200.', 'usage_limit' => '1', 'number_of_coupons' => 'unlimited', 'start_date' => '2018-09-01', 'end_date' => '2018-11-30', 'store_id' => '11']);
// 		$re = JselectLoyaltyUAT::list_coupon([]);
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'coupon_id' => 34,
// 				'campaign_id' => 9, 'name' => '￥100', 
// 				'type' => 'token', 'description' => '200', 
// 				'description_c' => '仅限广发</br>
// 									员工使用', 
// 				'usage_limit' => '1', 
// 				'number_of_coupons' => 'unlimited', 
// 				'start_date' => '2018-09-01', 'end_date' => '2018-11-30', 'store_id' => '14',
// 				'terms' => '凭电子券到广州天汇广场IGC三楼J SELECT门店即可享受满2000 减200优惠
// 							1. 有效期为：2018年9月1日到11月30日
// 							2. 实际消费满2000即可享受立减200优惠（可与其他活动共享）
// 							3. 电子券不可转让、退换或者兑换现金
// 							4. 本券仅适用于J SELECT中国大陆代理消费品业务'
// 				]);
// 		$re = JselectLoyalty::coupon_update([
// 				'coupon_id' => 23,
// 				'campaign_id' => 13, 'name' => '￥100',
// 				'type' => 'token', 'description' => '200',
// 				'description_c' => '仅限广发</br>
// 				员工使用',
// 				'usage_limit' => '1',
// 				'number_of_coupons' => 'unlimited',
// 				'start_date' => '2018-09-01', 'end_date' => '2018-11-30', 'store_id' => '11',
// 				'terms' => '凭电子券到广州天汇广场IGC三楼J SELECT门店即可享受满2000减200优惠
// 				1. 有效期为：2018年9月1日到11月30日
// 				2. 实际消费满2000即可享受立减200优惠（可与其他活动共享）
// 				3. 电子券不可转让、退换或者兑换现金
// 				4. 本券仅适用于J SELECT中国大陆代理消费品业务'
// 				]);
// 				$re = JselectLoyalty::list_coupon([]);
				
	// coupon_id 28 Artistic&Co. 面部产品体验券
// 				$re = JselectLoyalty::coupon_update([
// 				'campaign_id' => 4, 'coupon_id' => 20, 'type' => 'token', 
// 				'name' => '美肤疗程', 'description' => '美肤疗程', 'description_c' => '', 
// 				'autocreate' => '1', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited', 
// 				'start_date' => '2018-08-028 00:00:00', 'end_date' => '2099-12-31 23:59:59', 
// 				'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11', 'brand' => '1',
// 				'terms' => '1. 该体验券可享受的服务项目有：
// 								 a. 面部深层胶原蛋白重生（30分钟）; b. 面部深层清洁及营养导入（30分钟）; c. 局部脱毛疗程（20分钟）; d. 溢脂性脱发抑制及毛囊刺激疗程（15分钟）
// 							2. 体验券有效期：自收到优惠券的三个月内有效
// 							3. 体验券不可转让、退换或者兑换现金
// 							4. 本券仅适用于J SELECT中国大陆代理消费品业务
// 							5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 							6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权'
// 				]);
	
		// 3 earnrule 创建派发广法内部员工券的 rule
		// staging campaign_id = 9  创建结果 earnrule_id = 15
		// production campaign_id = 13 创建结果 earnrule_id = 5
// 				$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send GuangFa Employee Coupon', 'event' => 'Send GuangFa Employee Coupon', 'activity_rule' => 'all time']);
// 		$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => 15, 'limit_per_customer' => 1]);
// 				$re = JselectLoyalty::earnrule_create(['campaign_id' => 13, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send GuangFa Employee Coupon', 'event' => 'Send GuangFa Employee Coupon', 'activity_rule' => 'all time']);
// 			$re = JselectLoyalty::list_earnrule(['coupon_id' => 32]);
		// 4 add earnrule to item
		// staging earnrule_id = 15, coupon_id = 34 
		// staging earnrule_id = 5, coupon_id = 23
// 				$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => 15, 'coupon_id' => 34]);
// 		$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => 5, 'coupon_id' => 23]);
	
		// 5 staging 测试发卡
// 		$re = JselectLoyaltyUAT::customer_search([]);
// 		$re = JselectLoyaltyUAT::customer_get(['mobile' => '8613632704647']);
		// 测试发卡 chris->1166579683408607, aaron->001000112600, quincy->001000112601, fanny->001000112602 , Tomes->000017
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '000017', 'event' => 'Send GuangFa Employee Coupon']); // 测试发给罗涛
		// 正是发卡 chris->001000115759, cain->1346278872009810
// 		$re = JselectLoyalty::trigger_earnrule(['code' => '001000115821', 'event' => 'Send GuangFa Employee Coupon']); // 测试发给罗涛

		
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000115942','event' => 'Send GuangFa Employee Coupon']);
		
		// 测试核销	
// 		$re  = JselectLoyaltyUAT::store_get([]);
		// add hoc
// 				$re = JselectLoyaltyUAT::generator(['hash' => 'campaign/create_earnrule']);
		// 		$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => 6, 'active' => 'no']);
		// 		$re = JselectLoyaltyUAT::list_coupon(['coupon_id' => 21]);
		// 		$re = JselectLoyaltyUAT::customer_delete(['coupon_id' => '23']);
		// 				$re = JselectLoyalty::trigger_earnrule(['code' => '001000114445', 'event' => 'Send Ciabatta Bread Coupon']);
		// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112603', 'event' => 'Send Artistic&co Coupon']);
		// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => 'william13', 'event' => 'Dyson Survey Coupon']);
		// 		$re = JselectLoyaltyUAT::list_earnrule([]);
		// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => 2, 'coupon_id' => 4]);
		// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000115558']);
		// 				$re = JselectLoyalty::customer_search(['code' => '001000113705']);
		// 		$re = JselectLoyaltyUAT::customer_search(['wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA']);
// 		$re = JselectLoyalty::customer_update(['code' => '001000115736', 'wechat_openid' => '']);
		// 				$re = JselectLoyalty::customer_search(['mobile' => '18723836813']);
		//      cara 15918725639 tomes 8615196359975 aaron 18723836813
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'william13', 'wechat_openid' => 'o2Rmrtzjjg68MAirKb8XUJ7YdWc0', 'first_name' => 'william', 'last_name' => 'sun']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'q2', 'card_number' => 'q2', 'mobile' => '8613632704647', 'wechat_openid' => 'o2Rmrt53_MwNLLSIlWx8i_loINXA', 'first_name' => 'q', 'last_name' => 'q']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'f2', 'card_number' => 'f2', 'mobile' => '8613570341201', 'wechat_openid' => 'o2Rmrt4G8YQ32TGM-4a-XrL3JHoc', 'first_name' => 'f', 'last_name' => 'f']);
		// 		$re = JselectLoyaltyUAT::customer_create(['code' => 'a2', 'card_number' => 'a2', 'mobile' => '8613333333333', 'wechat_openid' => 'o2Rmrt5U54B4kkWj5YfQ67g3V3xM', 'first_name' => 'a', 'last_name' => 'a']);
		// 		$re = JselectLoyaltyUAT::customer_delete(['code' => '001000112581']);
		// 		$re = JselectLoyaltyUAT::coupon_update(['campaign_id'=> 7, 'coupon_id'=> 30, 'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14', 'autocreate' => '1', 'usage_limit' => '2']);
		// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => '001000112579']);
		$this->bp($re);
	}
	
	/*
	 * Sister Tao campaign*/
	public function actionP4()
	{
		header("Content-type: text/html; charset=utf-8");
		// 1
		// campaign
		//  staging campaign_id = 9
		//  production campaign_id = 13
		// 		$re = JselectLoyalty::campaign_new(['campaign_type' => 'reward', 'campaign_name_c'=> 'Temporary Campaign' ,'campaign_name' => 'Temporary Campaign']);
		// 		$re = JselectLoyaltyUAT::campaign_list([]);
	
		// 2
		// store
		// staging store_id = 9,10,11,12,15,13
		// production store_id = ？
		// $re = JselectLoyalty::store_create(['code' => 'LMZKF01', 'storename'=> '鲁马滋咖啡' ,'redeem_password' => '0823', 'address1' => '上海徐汇区兴国路372弄1号']);
// 			$re = JselectLoyaltyUAT::store_get([]);
// 			$re = JselectLoyalty::store_get([]);
	
	
		// staging store_id = 9,10,11,12,15,13  campaign_id = 9 创建结果 staging coupon_id = 35
		// production store_id = 10,6,7,8,9,12  campaign_id = 13 创建结果 staging coupon_id = 26 
// 			$re = JselectLoyaltyUAT::coupon_create(['campaign_id' => 9, 'name' => '星巴克中杯券', 'type' => 'token', 'description' => 'StarBucks', 'description_c' => '凭电子券到深圳和上海J SELECT门店即可领取星巴克中杯纸质券两张（先到先得，领完即止）', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited','start_date' => '0000-00-00', 'end_date' => '0000-00-00', 'store_id' => '9,10,11,12,15,13']);
// 			$re = JselectLoyalty::coupon_create(['campaign_id' => 13, 'name' => '星巴克中杯券', 'type' => 'token', 'description' => 'StarBucks', 'description_c' => '凭电子券到深圳和上海J SELECT门店即可领取星巴克中杯纸质券两张（先到先得，领完即止）', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited','start_date' => '0000-00-00', 'end_date' => '0000-00-00', 'store_id' => '10,6,7,8,9,12']);
// 				$re = JselectLoyaltyUAT::list_coupon([]);
// 				$re = JselectLoyalty::coupon_update([
// 								'coupon_id' => 26,
// 								'campaign_id' => 13, 'name' => '',
// 								'type' => 'token', 'description' => '星巴克中杯券',
// 								'description_c' => '',
// 								'usage_limit' => '1',
// 								'number_of_coupons' => 'unlimited',
// 								'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00', 
// 								'store_id' => '9,10,11,12,15,13',
// 								'terms' => '凭电子券到深圳和上海J SELECT门店即可领取星巴克中杯纸质券两张（先到先得，领完即止）
// 											条款及细则：
// 											1.  电子券不可转让、退换或者兑换现金
// 											2. 本券仅适用于J SELECT中国大陆代理消费品业务'
// 								]);
// 				创建帆布袋优惠券 coupon_id = 37
// 				$re = JselectLoyaltyUAT::coupon_update([ 
// 						'campaign_id' => 9, 'coupon_id' => 37, 'type' => 'token', 
// 						'name' => '帆布袋', 'description' => '定制帆布袋', 'description_c' => '免费领取',
// 						'usage_limit' => '1', 'number_of_coupons' => 'unlimited',
// 						'start_date' => '2018-09-19', 'end_date' => '2018-09-20',
// // 						'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 						'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13', 'terms' => '1.权益有效期：一年（时间按照领券日起算）
// 						活动期间，J SELECT会员到店即可领取定制购物袋一个
// 						2.本礼品券J SELECT全国门店通用
// 						3.每位会员仅可获赠会员尊享好礼一次
// 						4.会员尊享好礼数量有限，先到先得，送完即止
// 						5.会员尊享好礼不可转让、退换或者兑换现金
// 						6.本优惠仅适用于J SELECT中国大陆代理消费品业务
// 						7.捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 						8.如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);
// 				创建九折优惠券		coupon_id = 39	
// 				$re = JselectLoyaltyUAT::coupon_create([
// 						'campaign_id' => 9, 'type' => 'token', 
// 						'name' => '九折券', 'description' => '10', 'description_c' => '免费领取',
// 						'usage_limit' => '0', 'number_of_coupons' => 'unlimited', 'autocreate' => '1',
// 						'start_date' => '0000-00-00 00:00:00', 'end_date' => '0000-00-00 00:00:00',
// 						'store_id' => '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
// 						'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 						'terms' => '条款及细则:
// 						1. 体验券有效期截止为：2018年9月15日
// 						2. 体验券不可转让、退换或者兑换现金
// 						3. 本券仅适用于J SELECT中国大陆代理消费品业务
// 						4. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 						5. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权']);
	
		// 3 earnrule 创建派发广法内部员工券的 rule
		// staging campaign_id = 9  创建结果 earnrule_id = 17
		// production campaign_id = 13 创建结果 earnrule_id = 7
// 			$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9, 'active' => 'yes','limit_per_customer' => 2, 'description' => 'Send Sister Tao Coupon', 'event' => 'Send Sister Tao Coupon', 'activity_rule' => 'all time']);
// 			$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => 17, 'limit_per_customer' => 1]);
// 			$re = JselectLoyalty::earnrule_create(['campaign_id' => 13, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send Sister Tao Coupon', 'event' => 'Send Sister Tao Coupon', 'activity_rule' => 'all time']);
// 			$re = JselectLoyaltyUAT::list_earnrule(['earnrule_id' => 17]);
		// 4 add earnrule to item
		// staging earnrule_id = 17, coupon_id = 21, 35, 37, 39
		// staging earnrule_id = 7, coupon_id = 26
// 		$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => 17, 'coupon_id' => 37, 'validtime' => 365, 'unit' => 'day']);
// 			$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => 7, 'coupon_id' => 26]);		
// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => 17, 'coupon_id' => 39]);
		// 5 staging 测试发卡
		// 		$re = JselectLoyaltyUAT::customer_search([]);
// 				$re = JselectLoyalty::customer_get(['mobile' => '8613632704647']);
// 				$re = JselectLoyalty::get_coupon_codes(['code' => '001000115936']);
		// 测试发卡 
// 				$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000116245', 'event' => 'Send Sister Tao Coupon']); // 
// 		正是发卡 chris->001000115759, cain->1346278872009810
// 				$re = JselectLoyalty::trigger_earnrule(['code' => '001000116149', 'event' => 'Send Sister Tao Coupon']); // 测试发给罗涛	
		// 测试核销
		// 		$re  = JselectLoyaltyUAT::store_get([]);

		// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		// staging 创建姐妹淘 电子现金券 250 coupon_id = 42
// 		$re = JselectLoyaltyUAT::coupon_create(['campaign_id' => 9, 'name' => '250现金券', 'type' => 'coupon', 
// 				'description' => '现金券', 'description_c' => '现金券', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited',
// 				'start_date' => '0000-00-00', 'end_date' => '0000-00-00', 'store_id' => '9,10,11,12,15,13']);
		// production 创建姐妹淘 电子现金券 250 coupon_id = 25
// 				$re = JselectLoyalty::coupon_create(['campaign_id' => 13, 'name' => '250现金券', 'type' => 'coupon',
// 						'description' => '现金券', 'description_c' => '现金券', 'usage_limit' => '2', 'number_of_coupons' => 'unlimited',
// 						'start_date' => '0000-00-00', 'end_date' => '0000-00-00', 'store_id' => '9,10,11,12,15,13']);
// 				$re = JselectLoyaltyUAT::coupon_update([
// 						'coupon_id' => 42,
// 						'campaign_id' => 9, 'name' => '姐妹淘活动抵用券',
// 						'type' => 'coupon', 'description' => '250',
// 						'description_c' => '',
// 						'usage_limit' => '1',
// 						'number_of_coupons' => 'unlimited',
// 						'start_date' => '2018-09-01 00:00:00', 'end_date' => '2018-10-31 23:59:59', 'store_id' => '9,10,11,12,15,13',
// 						'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 						'terms' => '1. 现金券有效期截止为：2018年10月31日
// 									2. 本现金券广州及北京门店通用
// 									3. 现金券不可转让、退换或者兑换现金
// 									4. 本优惠仅适用于J SELECT中国大陆代理消费品业务
// 									5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 									6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权
// 									* 现金券使用规则：仅供J SELECT会员专享，当次核销可用'
// 						]);
// 		$re = JselectLoyalty::coupon_update([
// 								'coupon_id' => 25,
// 								'campaign_id' => 13, 'name' => '姐妹淘活动抵用券',
// 								'type' => 'coupon', 'description' => '250',
// 								'description_c' => '',
// 								'usage_limit' => '1',
// 								'number_of_coupons' => 'unlimited',
// 								'start_date' => '2018-09-01 00:00:00', 'end_date' => '2018-10-31 23:59:59', 'store_id' => '9,10,11,12,15,13',
// 								'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 								'terms' => '1. 现金券有效期截止为：2018年10月31日
// 											2. 本现金券广州及北京门店通用
// 											3. 现金券不可转让、退换或者兑换现金
// 											4. 本优惠仅适用于J SELECT中国大陆代理消费品业务
// 											5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 											6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权
// 											* 现金券使用规则：仅供J SELECT会员专享，当次核销可用'
// 								]);
		// staging创建发送 姐妹淘 现金券250 的rule earnrule_id = 19
// 		$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send Sister Tao Cash 250 Coupon', 'event' => 'Send Sister Tao Cash 250 Coupon', 'activity_rule' => 'all time']);
		// producttion创建发送 姐妹淘 现金券250 的rule earnrule_id = 6
// 		$re = JselectLoyalty::earnrule_create(['campaign_id' => 13, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send Sister Tao Cash 250 Coupon', 'event' => 'Send Sister Tao Cash 250 Coupon', 'activity_rule' => 'all time']);
// 		$re = JselectLoyalty::update_earnrule(['earnrule_id' => 6, 'limit_per_customer' => 2]);
		// 添加卡券到rule
// 		$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => 19, 'coupon_id' => 42]);
// 		$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => 6, 'coupon_id' => 25]);
// 		$re = JselectLoyalty::list_earnrule(['earnrule_id' => 7]);
	
// 		$re = JselectLoyalty::customer_get(['mobile' => '8613711971322']);
// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000116003']);
		// 测试发卡
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000115945', 'event' => 'Send Sister Tao Cash 250 Coupon']); //
		// 正式法券的list 13521419797->001000114418, 13811703131->001000116273, 15210358965->001000114321, 13911152273->001000114039, 13924198989->001000115913
		// 8613045888770->DC00101825807,DC00101825808
		// 8613711971322->DC00101825809
// 		$re = JselectLoyalty::trigger_earnrule(['code' => '001000116003', 'event' => 'Send Sister Tao Cash 250 Coupon']); //
		$this->bp($re);
	}

	public function actionStaging1()
	{
// 		$re = JselectLoyaltyUAT::store_get([]);
// 		$re = JselectLoyaltyUAT::customer_search([]);
// 		$re = JselectLoyaltyUAT::customer_get(['code'=>'001000120740']);
// 		$re = JselectLoyaltyUAT::customer_delete(['code' => '001000119972']);
		// 1 KPMG 员工内购优惠券
		// staging store_id = 13  campaign_id = 9 创建结果 coupon_id = 60
		
// 			   $re = JselectLoyaltyUAT::coupon_create([
// 				   		'campaign_id' => 9, 
// 				   		'name' => 'KPMG员工内购优惠券', 
// 				   		'type' => 'token', 
// 				   		'description' => 'IGC', 
// 				   		'description_c' => '亲临门店购买任意产品满2000即减200.(含当月促销价)', 
// 				   		'usage_limit' => '1', 
// 				   		'number_of_coupons' => 'unlimited', 
// 				   		'start_date' => '2018-11-27', 
// 				   		'end_date' => '2019-2-28', 
// 				   		'store_id' => '13'
// 			   		]);
		
// 				$re = JselectLoyaltyUAT::list_coupon([]);
				$re = JselectLoyaltyUAT::coupon_update([
						'coupon_id' => 60,
						'campaign_id' => 9, 'name' => '￥100',
						'type' => 'token', 'description' => '200',
								'description_c' => '仅限KPMG</br>
													员工使用',
								'usage_limit' => '1',
								'number_of_coupons' => 'unlimited',
								'start_date' => '2018-11-27 00：00：00', 'end_date' => '2019-02-28 00：00：00', 'store_id' => '13',
								'terms' => '凭电子券到深圳皇庭广场广场J SELECT门店即可享受满2000减200优惠
											1. 有效期为：发券之日起到2019年2月28日 
											2. 实际消费满2000即可享受立减200优惠
											3. 电子券不可与其他优惠券同时使用  
						                    4. 电子券不可转让、退换或者兑换现金
											5. 本券仅适用于J SELECT中国大陆代理消费品业务'
								]);
//      3. earnrule_id = 34
// 		$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9, 'active' => 'yes','limit_per_customer' => 1, 'description' => 'Send KPMG Coupon', 'event' => 'Send KPMG Coupon', 'activity_rule' => 'all time']);
// 		4. add coupon to rule
// 		$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => 34, 'coupon_id' => 60]);
// 		$re = JselectLoyaltyUAT::list_earnrule(['earnrule_id' => 34]);
//		5.testing send coupon
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000120740', 'event' => 'Send KPMG Coupon']); //
		echo '<pre>'; print_r($re);die;		
	}
	/**
	 * 创建coupon的字段对应关系
	 *
	 * name - 卷名，用来匹配 type
	 * description - 券的文字描述 / 或折扣数 / 或金钱数
	 * description_c - 核销按钮上方文字，可以为空
	 * terms - 使用条款
	 * brand - 1或空=自营门店 2=第三方门店
	 */
	public function actionT5()
	{
		header("Content-type: text/html; charset=utf-8");
// 		$re = JselectLoyaltyUAT::coupon_update([
// 				'campaign_id' => 18, 'coupon_id' => 42, 'type' => 'token', 'brand' => '1',
// 				'name' => '姐妹淘活动抵用券', 'description' => '250', 'description_c' => '',
// 				'usage_limit' => '1', 'number_of_coupons' => 'unlimited',
// 				'start_date' => '0000-00-00 00:00:00', 'end_date' => '2099-12-31 23:59:59',
// 				'store_id' => '9,10,11,12,15,13',
// 				'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 				'terms' => '1. 现金券有效期截止为：自收到优惠券的三个月内有效
// 							2. 本现金券J SELECT全国门店通用
// 							3. 现金券不可转让、退换或者兑换现金
// 							4. 本优惠仅适用于J SELECT中国大陆代理消费品业务
// 							5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 							6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权
// 							* 现金券使用规则：仅供J SELECT会员专享，当次核销可用'
// 				]);
// 		$re = JselectLoyaltyUAT::campaign_list(['campaign_id' => '9']);
		// UAT earnrule_id = 32
// 		$re = JselectLoyaltyUAT::earnrule_create(['campaign_id' => 9,
// 				'active' => 'yes', 'limit_per_customer' => 2, 
// 				'description' => 'Send Sister Tao Cash 250 Coupon', 
// 				'event' => 'Send Sister Cash 250 Coupon', 'activity_rule' => 'all time']);
// 		$re = JselectLoyaltyUAT::list_coupon(['coupon_id' => '30']);
// 		$re = JselectLoyaltyUAT::update_earnrule(['earnrule_id' => '19', 'limit_per_customer' => '2']);
// 		$re = JselectLoyaltyUAT::add_rule_to_item(['earnrule_id' => '32', 'coupon_id' => '42', 'validtime' => '90', 'unit' => 'day']);
// 		$re = JselectLoyaltyUAT::remove_rule_from_item(['earnrule_id' => '19', 'coupon_id' => '42']);
// 		$re = JselectLoyaltyUAT::list_earnrule(['earnrule_id' => '32']);
// 		$re = JselectLoyaltyUAT::customer_get(['mobile' => '8617713606662']);
// 		$re = JselectLoyaltyUAT::get_coupon_codes(['code' => 'test_ws001']);
// 		$re = JselectLoyaltyUAT::trigger_earnrule(['code' => '001000112603', 'event' => 'Send Sister Cash 250 Coupon']);
		$this->bp($re);
	}
	
	/**
	 * 新的姐妹陶Earnrule規則
	 */
	public function actionP5()
	{
		header("Content-type: text/html; charset=utf-8");
		// test account 001000112593;
// 		$re = JselectLoyalty::customer_get(['code' => '001000112593']);
// 		$re = JselectLoyalty::store_get([]);
// 		$re = JselectLoyalty::campaign_list([]);
// 		$re = JselectLoyalty::list_coupon(['coupon_id' => '25']);
// 		$re = JselectLoyalty::coupon_update([
// 				'campaign_id' => 13, 'coupon_id' => 25, 'type' => 'coupon', 'brand' => '1',
// 				'name' => '姐妹淘活动抵用券', 'description' => '250', 'description_c' => '',
// 				'usage_limit' => '1', 'number_of_coupons' => 'unlimited',
// 				'start_date' => '0000-00-00 00:00:00', 'end_date' => '2099-12-31 23:59:59',
// 				'store_id' => '1,2,3,4,5,6,7,8,9,10,11',
// 				'barcode_pattern' => json_encode(['pattern_type' => 'fixed', 'fixed_value' => '']),
// 				'terms' => '1. 现金券有效期截止为：自收到优惠券的三个月内有效
// 							2. 本现金券J SELECT全国门店通用
// 							3. 现金券不可转让、退换或者兑换现金
// 							4. 本优惠仅适用于J SELECT中国大陆代理消费品业务
// 							5. 捷成消費品零售(上海)有限公司保留随时修改本条款及细则、更改或终止优惠之权利，而不会作另行通知
// 							6. 如有任何争议，捷成消費品零售(上海)有限公司保留最终决定权
// 							* 现金券使用规则：仅供J SELECT会员专享，当次核销可用'
// 				]);
		// Production 新的姐妹陶Earnrule規則  earnrule_id = 8 
		// event = Send Sister Cash 250 Coupon
// 		$re = JselectLoyalty::earnrule_create(['campaign_id' => 13,
// 				'active' => 'yes', 'limit_per_customer' => 2,
// 				'description' => 'Send Sister Cash 250 Coupon', 
// 				'event' => 'Send Sister Cash 250 Coupon', 'activity_rule' => 'all time']);
		// 90天
// 		$re = JselectLoyalty::add_rule_to_item(['earnrule_id' => '8', 'coupon_id' => '25', 'validtime' => '90', 'unit' => 'day']);
// 		$re = JselectLoyalty::remove_rule_from_item(['earnrule_id' => '8', 'coupon_id' => '25']);
// 		$re = JselectLoyalty::list_earnrule(['earnrule_id' => '8']);
// 		$re = JselectLoyalty::customer_get(['mobile' => '8613910896565']);
// 		$re = JselectLoyalty::trigger_earnrule(['code' => '001000120509', 'event' => 'Send Sister Cash 250 Coupon']);
// 		$re = JselectLoyalty::get_coupon_codes(['code' => '001000120486']);
		$this->bp($re);
	}
	
	public function actionSendCoupon()
	{
		$codes = [
			'001000112580',
			'001000112666',
			'001000113578',
		];
		echo $codes[100];exit;
// 		for ($i = 100; $i < 218; $i++) {
// 			$re = JselectLoyalty::trigger_earnrule(['code' => $codes[$i], 'event' => 'Send Ciabatta Bread Coupon']);
// 			if ($re['status'] == 'success') {
// 				Log::debug($codes[$i] . ' ok');
// 			} else {
// 				Log::debug($codes[$i] . ' error');
// 			}
// 		}
// 		$this->bp($re);
	}
	
	public function actionCircle()
	{
// 		$re = Loyalty::customer_search(['offset' => '200', 'limit' => '200']);
// 		$customers = $re['result']['customers'];
// 		$this->bp($customers);
// 		for ($i = 800; $i <= 820; $i++) {
// 			$customer = Artistic::findOne($i);
// 			$re = Loyalty::trigger_earnrule(['code' => $customer->code, 'event' => 'Send Artistic&co Coupon']);
// 			if ($re['status'] == 'success') {
// 				$customer->status = 1;
// 				$customer->save();
// 			}
// 		}
// 		$this->bp($customer); 		
	}
}